import { LoginResult } from '@/api/login';
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';

export const useMemberStore = defineStore(
  'member',
  () => {
    const profile = ref({} as LoginResult);

    const setProfile = (newProfile: LoginResult) => {
      profile.value = newProfile;
    };

    const isLogin = computed(() => {
      return !!profile.value.token;
    });
    return { profile, setProfile, isLogin };
  },
  {
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key);
        },
        setItem(key, value) {
          uni.setStorageSync(key, value);
        },
      },
    },
  }
);
